from typing import List

class Solution:
    def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
        ans=[]
        def backtrack(combination,res,start):
            if res==0:
                ans.append(combination)
            else:
                for i in range(start,lenc):
                    if candidates[i]>res:
                        break
                    backtrack(combination+[candidates[i]],res-candidates[i],i)
        lenc=len(candidates)
        if lenc!=0:
            candidates.sort()
            backtrack([],target,0)
        return ans
